home *** CD-ROM | disk | FTP | other *** search
Wrap
Attribute VB_Name = "smtp" Option Explicit '--------------------------------------------------- 'SMTP.BAS 'Copyright 1996 by Carl Franklin 'Unauthorized reproduction in any medium of this 'source code is strictly prohibited without written 'permission from the author and John Wiley & Sons. '--------------------------------------------------- '-- CRLF Global vbCRLF As String '-- Holds the last command issued Global gszCommand As String '-- These variables hold fields of the ' messgae to be sent. Global gszTo As String Global gszFrom As String Global gszSubject As String Global gszMsg As String Global gszAttachedFiles() As String Global gnNumAttachedFiles As Integer Global Const gszAttachFile = "ATTACH.BIN" Function nSendFileAsMsg(szFileName As String, DSSocket As Control, lBlockSize As Long, szFrom As String, szTo As String, szSubject As String, szText As String) '*********************************************************** ' nSendFileAsMsg (by Carl Franklin) ' ' This function sends a file via email. ' If you want to send binary files you must ' first UUEncode them. Use the function ' nMakeMsgWithFiles (in UUCODE.BAS) to create ' a file that has a text message and one or ' more binary files embedded in it. ' ' Parameters: szFileName Full path and filename ' DSSocket Sockets control ' lBlockSize The maximum size of each block ' (default is 8192) ' szFrom Sender's email address ' szTo Recipient's email address ' szSubject Subject of the message ' szText Any text you want to tag on ' to the top of the message. '*********************************************************** Dim nMsgFile As Integer Dim szLine As String Dim szBuffer As String On Error GoTo nSendFileAsMsg_Error '-- Default block size = 8K If lBlockSize = 0 Then lBlockSize = 8192 End If '-- Open the message file nMsgFile = FreeFile Open szFileName For Binary As nMsgFile '-- szBuffer holds up to <blocksize> number of bytes ' and is sent when it becomes full. '-- Send the header first szBuffer = "DATE: " & Format$(Now, "dd mmm yy ttttt") & vbCRLF _ & "FROM: " & szFrom & vbCRLF _ & "TO: " & szTo & vbCRLF _ & "SUBJECT: " & szSubject & vbCRLF & vbCRLF _ & szText & vbCRLF SendData DSSocket, szBuffer '-- Send the file in chunks Do Until EOF(nMsgFile) szBuffer = Space$(lBlockSize) Get #nMsgFile, , szBuffer SendData DSSocket, szBuffer Loop Close nMsgFile '-- Send the final period. SendData DSSocket, vbCRLF & "." & vbCRLF Exit Function nSendFileAsMsg_Error: nSendFileAsMsg = Err On Error Resume Next Close nMsgFile Exit Function End Function Sub SendSMTPCommand(DSSock As Control, szCmd As String) '-- Save the last command sent gszCommand = szParseString(szCmd, " ", 1) '-- Send the command SendData DSSock, szCmd & vbCRLF End Sub